//
//  BillConfirmViewController.m
//  KiklinkApp
//
//  Created by LJC on 14/10/24.
//  Copyright (c) 2014年 Kiklink. All rights reserved.
//

#import "BillConfirmViewController.h"

#import "ImagesManager.h"
#import "UIColor+hex.h"

#import "PaymentConfirmViewController.h"

#import "API.h"

@interface BillConfirmViewController ()

@end

@implementation BillConfirmViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单确认";
    self.view.backgroundColor = [UIColor colorWithHexString:AppColor_BackGround];
    
    
    //BundleImages
    ImagesManager *imagesManager = [ImagesManager sharedImagesManager];
    
    
    //leftNavItem
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setFrame:CGRectMake(0, 0, NavBarHeight/4, NavBarHeight/2)];
    [backButton setBackgroundImage:[imagesManager back] forState:UIControlStateNormal];
    [backButton setBackgroundImage:[imagesManager backTapped] forState:UIControlStateHighlighted];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftNavBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftNavBarItem;
    
    
    //texts
    self.productName.text = self.name;
    self.priceLabel.text = self.expense;
    self.start.text = self.startStr;
    self.buyCount.text = [NSString stringWithFormat:@"%ld份",(long)self.boughtCount];
    
    
    //confirm
    [self.confirmBtn.layer setCornerRadius:5];
    [self.confirmBtn addTarget:self action:@selector(confirm) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - addOrder
- (void)addOrder
{
    [API addOrderWithProductId:[NSNumber numberWithInteger:self.productID] count:[NSNumber numberWithInteger:self.boughtCount] callback:^(int stateCode, NSString *word, id content) {}];
}
#pragma mark - addOrder End

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - back
- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - back End

#pragma mark -confirm
- (void)confirm
{
    PaymentConfirmViewController *paymentConfirmVC = [[PaymentConfirmViewController alloc] init];
    paymentConfirmVC.cost = self.expense;
    [self.navigationController pushViewController:paymentConfirmVC animated:YES];
}
#pragma mark -confirm

@end
